import { netWork } from '@/network/request.js';

class Axios { // Axios请求构造类
  constructor () {
  }

  getRequst (url, params = null) { // GET请求函数
    return netWork({
      url,
      method: 'GET',
      params
    })
  }
  
  getPost (url, data = null) { // POST请求函数
    return netWork({
      url,
      method: 'POST',
      data
    })
  }

  getPut (url, params = null, data = null) { // PUT请求函数
    // console.log(url, params);
    return netWork({
      url,
      method: 'PUT',
      params,
      data
    })
  }

  getDel (url) {
    return netWork({
      url,
      method: 'DELETE'
    })
  }

}


function getAllRole (pageObj) { // Home页面侧边栏请求
  return new Axios().getPost('role/findRolesByPage', pageObj);
}

function addRole (data) { // 添加role
  return new Axios().getPost('role/addRole', data);
}

function getRoleByrid (rid) {
  return new Axios().getRequst(`role/findRoleByRid`, {rid});
}

function updateRoleInfo (roleObj) {
  return new Axios().getPost(`role/updateRole`, roleObj);
}

function delRole(rid) {
  return new Axios().getDel(`role/delRole/${rid}`);
}

function delRemoveUserRight (roleId, rightId) {
  return new Axios().getDel(`roles/${roleId}/rights/${rightId}`);
}

function getRoleRightRequest () {
  return new Axios().getRequst('rights/tree');
}

function updateRolePermissions (roleObj) {
  return new Axios().getPost(`role/updateRolePermissions`, roleObj);
}

function getAllPermissions() {
  return new Axios().getRequst('permission/findAllPermissions');
}

function getPermissionByRid(rid) {
  return new Axios().getRequst(`permission/findPermissionByRid`, {rid});
}


export {
  getAllRole,
  addRole,
  getRoleByrid,
  updateRoleInfo,
  delRole,
  delRemoveUserRight,
  getRoleRightRequest,
  updateRolePermissions,
  getAllPermissions,
  getPermissionByRid
}


